package com.personal.book1.dao;

import com.personal.book1.model.BookInfo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

// 数据访问层
// 这里采用模拟数据的方式
@Repository
public class BookDao {
    public List<BookInfo> mockBookData() {
        List<BookInfo> bookInfos = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            // 先要有一本 “书”
            BookInfo bookInfo = new BookInfo();
            bookInfo.setBookId(i); // id递增
            bookInfo.setBookName("图书" + i);
            bookInfo.setBookAuthor("作者" + i);
            bookInfo.setStock(i*2 + 2);
            bookInfo.setPrice(new BigDecimal(new Random().nextInt(100)));
            bookInfo.setPublish("出版社" + i);
            bookInfo.setState(i % 2 == 0 ? 1 : 2); // 能整除以2的赋1，否则赋2
            bookInfos.add(bookInfo);
        }
        return bookInfos;
    }
}

